package com.godaiyu.lagou.service.impl;

import com.godaiyu.lagou.service.TimeSleepService;
import org.apache.dubbo.config.annotation.Service;

import java.util.Random;

/**
 * @author godai
 * @date 2021/2/25 21:42
 * @description
 */
@Service
public class RandomTimeSleepService implements TimeSleepService {
    @Override
    public String sleepA(String name, long maxSleepTime) {
        Random random = new Random();
        long a = Math.abs(random.nextLong() % maxSleepTime);
        try {
            System.out.println("sleepA sleep:" + a);
            Thread.sleep(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "OK-A";
    }

    @Override
    public String sleepB(String name, long maxSleepTime) {
        Random random = new Random();
        long a = Math.abs(random.nextLong() % maxSleepTime);
        try {
            System.out.println("sleepB sleep:" + a);
            Thread.sleep(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "OK-B";
    }

    @Override
    public String sleepC(String name, long maxSleepTime) {
        Random random = new Random();
        long a = Math.abs(random.nextLong() % maxSleepTime);
        try {
            System.out.println("sleepC sleep:" + a);
            Thread.sleep(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "OK-C";
    }
}
